package ${config.packageName}controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.validation.constraints.Positive;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ftwj.demo.aop.AnalysisActuator;
import com.ftwj.demo.base.util.PageInfoBean;
import com.ftwj.demo.config.swagger.DataType;
import com.ftwj.demo.config.swagger.HttpMethod;
import com.ftwj.demo.config.swagger.ParamType;
import ${config.packageName}entity.${className}Bean;
import ${config.packageName}service.${className}Service;
import com.ftwj.demo.utils.result.MessageEnum;
import com.ftwj.demo.utils.result.ResultBean;
import com.ftwj.demo.shiro.ShiroUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
*
* <p>Title: ${className}Controller</p>  
* <p>Description: 描述: XX前端控制器</p>
* <p>Copyright: Copyright (c) 2020 </p>  
* <p>Company: ${config.company}</p>    
* @author ${config.author}
* @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}
* @version V1.0
*/
@RestController 
@RequestMapping("/${lowerClassName}")
@Api(tags="接口名", value="接口描述")
@Validated
public class ${className}Controller {

	@Autowired
	private ${className}Service service;

	/**
	 * @author  ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}
	 * @version 1.0
	 */
	@GetMapping("page/{current}/{size}")
	@ApiOperation(value="分页列表数据条件查询（TODO）", notes="备注",code=0,httpMethod=HttpMethod.GET)
	@ApiImplicitParams({
    	@ApiImplicitParam(name="current", value="当前页数", dataType=DataType.INTEGER, paramType=ParamType.PATH, defaultValue="1")
    	,@ApiImplicitParam(name="size", value="每页显示条数", dataType=DataType.INTEGER, paramType=ParamType.PATH, defaultValue="10")
    })
	public ResultBean<?> page(@PathVariable Integer current, @PathVariable Integer size, @RequestParam(name="",required=false)) {
		PageInfoBean pageInfo = new PageInfoBean();
		pageInfo.setPerPage(size).setPerPage(size);
		${className}Bean bean=new ${className}Bean();
		pageInfo = service.pageByExample(bean,pageInfo);
		return ResultBean.success(pageInfo);
	}
	
	/**
	 * @author  ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}
	 * @version 1.0
	 */
	@GetMapping("/list")
	@ApiOperation(value="列表条件查询（TODO）", notes="备注",code=0, httpMethod=HttpMethod.GET)
    @ApiImplicitParams({
    	@ApiImplicitParam(name="", value="", dataType=DataType.INTEGER, paramType=ParamType.QUERY, required=false)
    	,@ApiImplicitParam(name="", value="", dataType=DataType.STRING, paramType=ParamType.QUERY, required=false)
    })
	public ResultBean<?> list(@RequestParam(name="",required=false)) {
		${className}Bean bean=new ${className}Bean();
		List<ScheduleJobBean> data=service.findListByExample(bean);
		List<Map<String, Object>> data=service.findListMapByExample(bean);
		return ResultBean.success(data);
	}
	
	/**
	 * @author  ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}
	 * @version 1.0
	 */
	@GetMapping("/info/{id}")
	@ApiOperation(value="详细信息（DONE）", notes="备注",code=0,httpMethod=HttpMethod.GET)
	@ApiImplicitParams({
		@ApiImplicitParam(name="id", value="编号", dataType=DataType.INTEGER, paramType=ParamType.PATH, required=false)
	})
	public ResultBean<${className}Bean> info(@PathVariable@Positive Integer id){
		${className}Bean data = service.find(id);
		return ResultBean.success(data);
	}
	
	/**
	 * @author ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}
	 * @version 1.0
	 */
	@PostMapping("/insert")
	@ApiOperation(value="数据新增（DONE）", notes="数据",code=0,httpMethod=HttpMethod.POST)
	@AnalysisActuator //日志记录自定义注解
	public ResultBean<?> insert(@RequestBody@Validated ${className}Bean entity){
		entity.setCreateUser(ShiroUtil.getUserId()).setCreateTime(new Date());
		if(service.add(entity)>0) {
			return ResultBean.success();
		}else {
			return ResultBean.error(MessageEnum.SERVER_FAILED);
		}
	}
	
	/**
	 * @author ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}  
	 * @version 1.0
	 */
	@PutMapping("/edit")
	@ApiOperation(value="XX修改", notes="数据",code=0,httpMethod=HttpMethod.PUT)
	@AnalysisActuator //日志记录自定义注解
	public ResultBean<?> edit(@RequestBody@Validated ${className}Bean entity){
		entity.setCreateUser(ShiroUtil.getUserId()).setCreateTime(new Date());//主键必须存在
		if(service.save(entity)>0) {
			return ResultBean.success();
		}else {
			return ResultBean.error(MessageEnum.SERVER_FAILED);
		}
	}
	
	/**
	 * @author ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}  
	 * @version 1.0
	 */
	@DeleteMapping("/delete/{id}")
	@ApiOperation(value="XX数据删除(逻辑)", notes="数据",code=0,httpMethod=HttpMethod.DELETE)
	@ApiImplicitParams({
		@ApiImplicitParam(name="id", value="XX编号", dataType=DataType.INTEGER, paramType=ParamType.PATH)
	})
	@AnalysisActuator //日志记录自定义注解
	public ResultBean<?> delete(@Positive(message="ID必须是大于0的整数")@PathVariable Integer id) {
		if(service.remo(id)>0) {
			return ResultBean.success();
		}else {
			return ResultBean.error(MessageEnum.SERVER_FAILED);
		}
	}
	
	/**
	 * @author ${config.author}
	 * @date ${.now?datetime?string("yyyy年MM月dd日 HH:mm:ss")}  
	 * @version 1.0
	 */
	@DeleteMapping("/deles")
	@ApiOperation(value="数据批量删除", notes="数据",code=0,httpMethod=HttpMethod.DELETE)
	@AnalysisActuator //日志记录自定义注解
	public ResultBean<?> deles(@RequestBody Integer[] ids){
		Object keys=ids;
		service.remoByIds(keys);
		return ResultBean.success();
	}
}
